package servlet;

import dao.UserDaoImpl;
import impl.BaoDaoserviceImpl;
import pojo.AirQualityIndex;
import service.BaoDaoservice;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/upDateServlet")
public class upDateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AirQualityIndex air = new AirQualityIndex();
        System.out.println("进入更新");
        int id = Integer.parseInt(request.getParameter("id"));
        String districtId = request.getParameter("quyu");
        String monitorTime = request.getParameter("monitorTime");
        int pm10 = Integer.parseInt(request.getParameter("pm10"));
        int pm25 = Integer.parseInt(request.getParameter("pm25"));
        String monitoringStation = request.getParameter("monitoringStation");

        //获取当前时间
        Date nowTime = new Date(System.currentTimeMillis());
        SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String retStrFormatNowDate = sdFormatter.format(nowTime);
        System.out.println(retStrFormatNowDate);
        BaoDaoservice aq =  new BaoDaoserviceImpl();
        air.setId(id);
        air.setDistrictId(districtId);
        air.setMonitorTime(monitorTime);
        air.setPm10(pm10);
        air.setPm25(pm25);
        air.setMonitoringStation(monitoringStation);
        air.setLastModifyTime(retStrFormatNowDate);
        aq.update(air);
        response.sendRedirect("indexSelect");


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}